﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.css {
    import reprise.utils.*;

    public class CSSPropertyParser {

        public static var KNOWN_PROPERTIES:Array = null;
        public static var INHERITABLE_PROPERTIES:Object = null;

        protected static function strToProperty(_arg1:String, _arg2:String=null):Object{
            var _local3:CSSProperty = new CSSProperty();
            var _local4:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            _arg1 = StringUtil.trim(_local4.result);
            _local3.setImportant(_local4.important);
            _local3.setCSSFile(_arg2);
            if (CSSParsingHelper.valueShouldInherit(_arg1)){
                _local3.setInheritsValue(true);
            };
            return ({property:_local3, filteredString:_arg1});
        }
        protected static function strToRectParsingResult(_arg1:String, _arg2:String, _arg3:String, _arg4:String, _arg5:Function):CSSParsingResult{
            var _local11:CSSProperty;
            var _local12:CSSProperty;
            var _local13:CSSProperty;
            var _local14:CSSProperty;
            var _local6:Object = strToProperty(_arg1, _arg2);
            var _local7:CSSProperty = _local6.property;
            _arg1 = StringUtil.trim(_local6.filteredString);
            var _local8:CSSParsingResult = new CSSParsingResult();
            if (_local7.inheritsValue()){
                _local8.addPropertyForKey(_local7, ((_arg3 + "Top") + _arg4));
                _local8.addPropertyForKey(_local7, ((_arg3 + "Right") + _arg4));
                _local8.addPropertyForKey(_local7, ((_arg3 + "Bottom") + _arg4));
                _local8.addPropertyForKey(_local7, ((_arg3 + "Left") + _arg4));
            };
            if (_arg1.length == 0){
                return (null);
            };
            var _local9:Array = _arg1.split(" ");
            var _local10:Boolean = _local7.important();
            switch (_local9.length){
                case 1:
                    _local14 = _arg5(_local9[0], _arg2);
                    _local13 = _local14;
                    _local12 = _local13;
                    _local11 = _local12;
                    break;
                case 2:
                    _local13 = _arg5(_local9[0], _arg2);
                    _local11 = _local13;
                    _local14 = _arg5(_local9[1], _arg2);
                    _local12 = _local14;
                    break;
                case 3:
                    _local11 = _arg5(_local9[0], _arg2);
                    _local14 = _arg5(_local9[1], _arg2);
                    _local12 = _local14;
                    _local13 = _arg5(_local9[2], _arg2);
                    break;
                case 4:
                    _local11 = _arg5(_local9[0], _arg2);
                    _local12 = _arg5(_local9[1], _arg2);
                    _local13 = _arg5(_local9[2], _arg2);
                    _local14 = _arg5(_local9[3], _arg2);
                    break;
                default:
                    log((("w Wrong number of parameters for CSSProperty rect with name\"" + _arg3) + "\""));
                    return (_local8);
            };
            _local11.setImportant(_local10);
            _local12.setImportant(_local10);
            _local13.setImportant(_local10);
            _local14.setImportant(_local10);
            _local8.addPropertyForKey(_local11, ((_arg3 + "Top") + _arg4));
            _local8.addPropertyForKey(_local12, ((_arg3 + "Right") + _arg4));
            _local8.addPropertyForKey(_local13, ((_arg3 + "Bottom") + _arg4));
            _local8.addPropertyForKey(_local14, ((_arg3 + "Left") + _arg4));
            return (_local8);
        }
        protected static function strToFloatProperty(_arg1:String, _arg2:String=null):CSSProperty{
            var _local3:Object = strToNumericProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            if (_local4.inheritsValue()){
                return (_local4);
            };
            if ((((_arg1 == "auto")) || (_local4.isCalculation()))){
                _local4.setSpecifiedValue(_arg1);
                return (_local4);
            };
            _local4.setSpecifiedValue(parseFloat(_arg1));
            return (_local4);
        }
        public static function extractBorderStyleFromString(_arg1:String, _arg2:String=null):Object{
            var _local3:RegExp = /none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset/;
            var _local4:Object = {borderStyle:"none"};
            var _local5:Array = _arg1.match(_local3);
            if (_local5){
                _local4.borderStyle = strToStringProperty(_local5[0], _arg2);
                _local4.filteredString = (_arg1.substr(0, _local5.index) + _arg1.substr((_local5.index + _local5[0].length)));
            } else {
                _local4.borderStyle = strToStringProperty("none", _arg2);
                _local4.filteredString = _arg1;
            };
            return (_local4);
        }
        protected static function strToBoolProperty(_arg1:String, _arg2:String=null, _arg3:Array=null):CSSProperty{
            var _local4:Object = strToProperty(_arg1, _arg2);
            var _local5:CSSProperty = _local4.property;
            _arg1 = _local4.filteredString;
            if (_local5.inheritsValue()){
                return (_local5);
            };
            if (_arg3 == null){
                _arg3 = ["true", "1"];
            };
            var _local6 = (_arg3.indexOf(_arg1) > -1);
            _local5.setSpecifiedValue(_local6);
            return (_local5);
        }
        protected static function strToColorProperty(_arg1:String, _arg2:String=null):CSSProperty{
            var _local3:Object = strToProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            if (_local4.inheritsValue()){
                return (_local4);
            };
            _local4.setSpecifiedValue(CSSParsingHelper.parseColor(_arg1));
            return (_local4);
        }
        public static function extractDurationFromString(_arg1:String, _arg2:String=null):Object{
            var _local3:Object = {};
            var _local4:Array = _arg1.match(CSSParsingHelper.durationExpression);
            if (_local4){
                _local3.duration = strToDurationProperty(_local4[0], _arg2);
                _local3.filteredString = (_arg1.substr(0, _local4.index) + _arg1.substr((_local4.index + _local4[0].length)));
            } else {
                _local3.filteredString = _arg1;
            };
            return (_local3);
        }
        public static function extractFunctionLiteralFromString(_arg1:String, _arg2:String, _arg3:Boolean=true):Object{
            var _local6:int;
            var _local4:Object = {};
            var _local5:int = _arg1.indexOf((_arg2 + "("));
            if (_local5 != -1){
                _local6 = _arg1.indexOf(")", _local5);
                if (_arg3){
                    _local4.functionLiteral = _arg1.substring(_local5, (_local6 + 1));
                } else {
                    _local4.functionLiteral = _arg1.substring(((_local5 + _arg2.length) + 1), _local6);
                };
                _local4.filteredString = (_arg1.substr(0, _local5) + _arg1.substr((_local6 + 1)));
            } else {
                _local4.filteredString = _arg1;
            };
            return (_local4);
        }
        protected static function strToStringProperty(_arg1:String, _arg2:String=null):CSSProperty{
            var _local3:Object = strToProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            if (_local4.inheritsValue()){
                return (_local4);
            };
            _local4.setSpecifiedValue(_arg1);
            return (_local4);
        }
        public static function extractBorderWidthFromString(_arg1:String, _arg2:String=null):Object{
            var _local3:RegExp = /\d+px|d+%0/;
            var _local4:Object = {};
            var _local5:Array = _arg1.match(_local3);
            if (_local5){
                _local4.borderWidth = strToIntProperty(_local5[0], _arg2);
                _local4.filteredString = (_arg1.substr(0, _local5.index) + _arg1.substr((_local5.index + _local5[0].length)));
            } else {
                _local4.borderWidth = strToIntProperty("1px", _arg2);
                _local4.filteredString = _arg1;
            };
            return (_local4);
        }
        protected static function strToDurationProperty(_arg1:String, _arg2:String=null):CSSProperty{
            var _local3:Object = strToProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            if (_local4.inheritsValue()){
                return (_local4);
            };
            var _local5:int = _arg1.length;
            while ("0123456789.".indexOf(_arg1.charAt((_local5 - 1))) == -1) {
                _local5--;
            };
            var _local6 = "ms";
            if (_local5 < _arg1.length){
                _local6 = _arg1.substr(_local5);
            };
            var _local7:Number = parseFloat(_arg1);
            switch (_local6){
                case "s":
                    _local7 = (_local7 * 1000);
                    break;
                case "ms":
            };
            _local4.setUnit("ms");
            _local4.setSpecifiedValue(_local7);
            return (_local4);
        }
        protected static function strToNumericProperty(_arg1:String, _arg2:String=null):Object{
            var _local3:Object = strToProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            if (_local4.inheritsValue()){
                return (_local3);
            };
            if (_arg1.indexOf("calc(") > -1){
                _local4.setIsCalculation(true);
            } else {
                _local4.setUnit(CSSParsingHelper.extractUnitFromString(_arg1));
            };
            return (_local3);
        }
        protected static function strToURLProperty(_arg1:String, _arg2:String=null):CSSProperty{
            var _local3:Object = strToProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            if (_local4.inheritsValue()){
                return (_local4);
            };
            _local4.setSpecifiedValue(CSSParsingHelper.parseURL(_arg1, _arg2));
            return (_local4);
        }
        public static function extractPropertyNameFromString(_arg1:String):Object{
            var _local4:String;
            var _local2:Object = {};
            var _local3:Array = _arg1.match(CSSParsingHelper.propertyNameExpression);
            if (_local3){
                _local4 = _local3[0];
                _local2.propertyName = CSSParsingHelper.camelCaseCSSValueName(_local4);
                _local2.filteredString = (_arg1.substr(0, _local3.index) + _arg1.substr((_local3.index + _local3[0].length)));
            } else {
                _local2.filteredString = _arg1;
            };
            return (_local2);
        }
        protected static function strToIntProperty(_arg1:String, _arg2:String=null):CSSProperty{
            var _local3:Object = strToNumericProperty(_arg1, _arg2);
            var _local4:CSSProperty = _local3.property;
            _arg1 = _local3.filteredString;
            if (_local4.inheritsValue()){
                return (_local4);
            };
            if ((((_arg1 == "auto")) || (_local4.isCalculation()))){
                _local4.setSpecifiedValue(_arg1);
                return (_local4);
            };
            _local4.setSpecifiedValue(int(parseInt(_arg1)));
            return (_local4);
        }

    }
}//package reprise.css 
